import { createStore } from 'vuex'

const store = createStore({
	state: {
		hasLogin: false,
		openid: null
	},
	mutations: {
		login(state, openid) {
			state.hasLogin = true;
			state.openid = openid
		}
	},
	getters: {
		
	},
	actions: {
		getUserOpenId: async function({ commit, state }) {
			return await new Promise((resolve, reject) => {
				if (state.openid) {
					resolve(state.openid)
				} else {
					uni.login({
						success: code => {
							
						},
						fail: err => {
							reject(err)
						}
					})
				}
			})
		}
	}
})

export default store